#include "StdAfx.h"
#include "GameObject.h"
#include "Messenger.h"
#include "TimerController.h"

ObjectId GameObject::_globalid = 0;

GameObject::GameObject(ObjectClass cls)
{
	_Id = _globalid++;
	_Class = cls;
}

GameObject::~GameObject(void)
{
}

void GameObject::Connect(GameObject * obj)
{
	_ConnectedObjects.push_back(obj);
}

void GameObject::Signal(SignalCode code)
{
	if (_ConnectedObjects.size() == 0)
		return;

	GameObject::List * clone = new GameObject::List;
	for (GameObject::List::iterator it = _ConnectedObjects.begin(); it != _ConnectedObjects.end(); it++)
		clone->push_back(*it);

	shared_ptr<Sgn> sgn(new Sgn(this, clone, code));
	Messenger::GetInstance()->AddSignal(sgn);
}

void GameObject::SetTimer(UINT every, UINT id)
{
	TimerController::GetInstance()->SetTimer(every, id, this);
}

